﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.NoAnswerMessageInChannels.Service
{
    public class NoAnswerMessageInChannelAppService : BaseAppService, INoAnswerMessageInChannelAppService
    {
        private INoAnswerMessageInChannelDomainService _domainService;

        public NoAnswerMessageInChannelAppService(INoAnswerMessageInChannelDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.NOANSWERMESSAGEINCHANNEL, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.NOANSWERMESSAGEINCHANNEL, AuditAction.CREATE)]
        public Dto.NoAnswerMessageInChannelDto Add(Guid botId, NoAnswerMessageInChannelCreateDto dto)
        {
            var obj = Mapper.Map<NoAnswerMessageInChannel>(dto);
            obj.Id = Guid.NewGuid();
            obj.BotId = botId;
            NoAnswerMessageInChannel noAnswerMessageInChannel = _domainService.Create(obj);
            return Mapper.Map<Dto.NoAnswerMessageInChannelDto>(noAnswerMessageInChannel);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.NOANSWERMESSAGEINCHANNEL, AuditAction.UPDATE)]
        public Dto.NoAnswerMessageInChannelDto Update(Guid id, NoAnswerMessageInChannelUpdateDto dto)
        {
            dto.Id = id;
            NoAnswerMessageInChannel noAnswerMessageInChannel = _domainService.Update(Mapper.Map<NoAnswerMessageInChannelUpdateBo>(dto));
            return Mapper.Map<Dto.NoAnswerMessageInChannelDto>(noAnswerMessageInChannel);
        }

        public Dto.NoAnswerMessageInChannelDto Get(Guid id)
        {
            NoAnswerMessageInChannel noAnswerMessageInChannel = _domainService.Get(id);
            return Mapper.Map<Dto.NoAnswerMessageInChannelDto>(noAnswerMessageInChannel);
        }

        public IEnumerable<Dto.NoAnswerMessageInChannelDto> GetByBotId(Guid botId)
        {
            IEnumerable<NoAnswerMessageInChannel> list = _domainService.GetByBotId(botId);
            return Mapper.Map<IEnumerable<Dto.NoAnswerMessageInChannelDto>>(list);
        }
    }
}
